#include "stdafx.h"
#include <stdio.h>
#include <allegro5/allegro.h>
#include <allegro5/allegro_image.h>

const float FPS = 60;
const int SCREEN_W = 640;
const int SCREEN_H = 480;
const int BOUNCER_SIZE = 32;
 
int main(int argc, char **argv)
{
<<<<<<< .mine

	//Create a display and an event queue
	ALLEGRO_DISPLAY *display = NULL;
	ALLEGRO_EVENT_QUEUE *event_queue = NULL;
	ALLEGRO_BITMAP * testBMP = NULL;

	//Test if allegro failed to initiliaze, if it did print a message to the console and leave with error code -1

	
	if(!al_init()) {
		fprintf(stderr, "failed to initialize allegro!\n");
		return -1;
	}

	al_init_image_addon();


	//Set the display by assisnging it the properties returned from the function al_create_display(640, 480) this sets the display to a resoloution of 640x480
	display = al_create_display(640, 480);

	//check to see if the display was properly set
	if(!display) {
		fprintf(stderr, "failed to create display!\n");
		return -1;
	}



	testBMP = al_load_bitmap("Media/Grass.bmp");

	if(!testBMP)
	{
		fprintf(stderr,"failed to initialize testBMP!\n");
		return -1;

	}

	//Create an even queue, event queues can be filled with different evens that happen from sources, sources include keyboard, mouse and display, we will use display
	event_queue = al_create_event_queue();

	//We check if the queue was set properly
	if(!event_queue) {
		fprintf(stderr, "failed to create event_queue!\n");
		al_destroy_display(display);
		return -1;
	}


	//We set the queue to watch all the events from the source, our source is the display, so resizing or closing the window would be an event for the display
	al_register_event_source(event_queue, al_get_display_event_source(display));

	//We clear the screen to the colour black
	al_clear_to_color(al_map_rgb(0,0,0));

	//We swap the drawing buffer to show our changes since we last swapped buffers, search up double buffering to find out more about what this means
	al_flip_display();


	while(1)
	{
		//We createa an event to hold the event
		ALLEGRO_EVENT ev;
		//A timeout to be initiliased 
		ALLEGRO_TIMEOUT timeout;
		//Here we initliase timeout and set it to 0.06, or 60 miliseconds
		al_init_timeout(&timeout, 0.06);

		//Here the bool is assigned either true of false depending if the event queue is updated with an event or it gets set to false if the timeout occurs before the event finishes.
		bool got_event = al_wait_for_event_until(event_queue, &ev, &timeout);

		//We check if the event was close
		if(got_event && ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) {

			//This ends the program loop, closing the program
			break;
		}

		//Draw bitmap testBMP which containts testBMP to the screen at coords 50,50 then swap buffers to show changes
		al_draw_bitmap(testBMP, 0.0 ,0.0,0);
		al_draw_bitmap(testBMP, 237.0 ,0.0,0);
		al_draw_bitmap(testBMP, 0.0 ,216.0,0);
		al_draw_bitmap(testBMP, 237.0 ,216.0,0);
		al_flip_display();
	}

	//Destroy display object and queue object
	al_destroy_display(display);
	al_destroy_event_queue(event_queue);


	return 0;
=======
   ALLEGRO_DISPLAY *display = NULL;
   ALLEGRO_EVENT_QUEUE *event_queue = NULL;
   ALLEGRO_TIMER *timer = NULL;
   ALLEGRO_BITMAP *bouncer = NULL;
   float bouncer_x = SCREEN_W / 2.0 - BOUNCER_SIZE / 2.0;
   float bouncer_y = SCREEN_H / 2.0 - BOUNCER_SIZE / 2.0;
   bool redraw = true;
 
   if(!al_init()) {
      fprintf(stderr, "failed to initialize allegro!\n");
      return -1;
   }
 
   if(!al_install_mouse()) {
      fprintf(stderr, "failed to initialize the mouse!\n");
      return -1;
   }
 
   timer = al_create_timer(1.0 / FPS);
   if(!timer) {
      fprintf(stderr, "failed to create timer!\n");
      return -1;
   }
 
   display = al_create_display(SCREEN_W, SCREEN_H);
   if(!display) {
      fprintf(stderr, "failed to create display!\n");
      al_destroy_timer(timer);
      return -1;
   }
 
   bouncer = al_create_bitmap(BOUNCER_SIZE, BOUNCER_SIZE);
   if(!bouncer) {
      fprintf(stderr, "failed to create bouncer bitmap!\n");
      al_destroy_display(display);
      al_destroy_timer(timer);
      return -1;
   }
 
   al_set_target_bitmap(bouncer);
 
   al_clear_to_color(al_map_rgb(255, 0, 255));
 
   al_set_target_bitmap(al_get_backbuffer(display));
 
   event_queue = al_create_event_queue();
   if(!event_queue) {
      fprintf(stderr, "failed to create event_queue!\n");
      al_destroy_bitmap(bouncer);
      al_destroy_display(display);
      al_destroy_timer(timer);
      return -1;
   }
 
   al_register_event_source(event_queue, al_get_display_event_source(display));
 
   al_register_event_source(event_queue, al_get_timer_event_source(timer));
 
   al_register_event_source(event_queue, al_get_mouse_event_source());
 
   al_clear_to_color(al_map_rgb(0,0,0));
 
   al_flip_display();
 
   al_start_timer(timer);
 
   while(1)
   {
      ALLEGRO_EVENT ev;
      al_wait_for_event(event_queue, &ev);
 
      if(ev.type == ALLEGRO_EVENT_TIMER) {
         redraw = true;
      }
      else if(ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) {
         break;
      }
      else if(ev.type == ALLEGRO_EVENT_MOUSE_AXES ||
              ev.type == ALLEGRO_EVENT_MOUSE_ENTER_DISPLAY) {
 
         bouncer_x = ev.mouse.x;
         bouncer_y = ev.mouse.y;
      }
      else if(ev.type == ALLEGRO_EVENT_MOUSE_BUTTON_UP) {
          break;
      }
 
      if(redraw && al_is_event_queue_empty(event_queue)) {
         redraw = false;
 
         al_clear_to_color(al_map_rgb(0,0,0));
 
         al_draw_bitmap(bouncer, bouncer_x, bouncer_y, 0);
 
         al_flip_display();
      }
   }
 
   al_destroy_bitmap(bouncer);
   al_destroy_timer(timer);
   al_destroy_display(display);
   al_destroy_event_queue(event_queue);
 
   return 0;
>>>>>>> .r15
}